//
// Created by 谢哲 on 2021/4/19.
//

#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    vector<vector<bool>> vdata(10, vector<bool>(10, false));
    int cx = 0, cy = 0, fx = 0, fy = 0;

    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    for (int i=0;i<10;++i) {
        for (int j=0;j<10;++j) {
            char c;
            cin>>c;
            if (c=='.') {
                continue;
            }
            else if (c=='*') {
                vdata[i][j] = true;
            }
            else if (c=='C') {
                cx = i, cy = j;
            }
            else {
                fx = i, fy = j;
            }
        }
    }

    set<vector<int>> path;

    int cd = 0, fd = 0;
    int cnt = 0;

    while(cx!=fx||cy!=fy) {
        int ncx = cx+dx[cd], ncy = cy+dy[cd];
        if (ncx<0||ncx>=10||ncy<0||ncy>=10||vdata[ncx][ncy]) {
            cd = (cd+1)%4;
        }
        else{
            cx = ncx, cy = ncy;
        }

        int nfx = fx+dx[fd], nfy = fy+dy[fd];
        if (nfx<0||nfx>=10||nfy<0||nfy>=10||vdata[nfx][nfy]) {
            fd = (fd+1)%4;
        }
        else {
            fx = nfx, fy = nfy;
        }
        ++cnt;

        vector<int> cur_pos = {cx, cy, fx, fy, cd, fd};

        if (path.find(cur_pos)!=path.end()) {
            cout<<0;
            return 0;
        }
        path.insert(cur_pos);
    }

    cout << cnt;

    return 0;
}
